package com.baselibrary.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import com.baselibrary.R
import com.baselibrary.utils.GlideUtils
import java.util.*

/**
 * @author: 关忆北、
 * @date: 2022/5/30
 * @Des：头像叠加
 */
class HeadCladView : LinearLayout {
    private lateinit var mCircleHeadCladOne: CircleImageView
    private lateinit var mCircleHeadCladTwo: CircleImageView
    private lateinit var mCircleHeadCladThree: CircleImageView
    private lateinit var mCircleHeadCladFour: CircleImageView
    private lateinit var mCircleHeadCladFive: CircleImageView

    constructor(context: Context) : super(context) {
        initView(context)
    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        initView(context)
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        initView(context)
    }

    private fun initView(context: Context) {
        val inflate = LayoutInflater.from(context).inflate(R.layout.item_head_clad, this)
        mCircleHeadCladOne = findViewById<View>(R.id.circle_head_clad_one) as CircleImageView
        mCircleHeadCladTwo = findViewById<View>(R.id.circle_head_clad_two) as CircleImageView
        mCircleHeadCladThree = findViewById<View>(R.id.circle_head_clad_three) as CircleImageView
        mCircleHeadCladFour = findViewById<View>(R.id.circle_head_clad_four) as CircleImageView
        mCircleHeadCladFive = findViewById<View>(R.id.circle_head_clad_five) as CircleImageView
    }

    /**
     * @param list
     * @param sortB = true 将集合倒叙
     */
    fun setData(list: ArrayList<String>?) {
        if (list.isNullOrEmpty()) {
            visibility = GONE
            mCircleHeadCladOne.visibility = GONE
            mCircleHeadCladTwo.visibility = GONE
            mCircleHeadCladThree.visibility = GONE
            mCircleHeadCladFour.visibility = GONE
            mCircleHeadCladFive.visibility = GONE
            return
        }
        when (list.size) {
            1 -> {
                mCircleHeadCladOne.visibility = VISIBLE
                mCircleHeadCladTwo.visibility = GONE
                mCircleHeadCladThree.visibility = GONE
                mCircleHeadCladFour.visibility = GONE
                mCircleHeadCladFive.visibility = GONE
                GlideUtils.loadImg_101(context.applicationContext, list[0], mCircleHeadCladOne)
            }
            2 -> {
                mCircleHeadCladOne.visibility = VISIBLE
                mCircleHeadCladTwo.visibility = VISIBLE
                mCircleHeadCladThree.visibility = GONE
                mCircleHeadCladFour.visibility = GONE
                mCircleHeadCladFive.visibility = GONE
                GlideUtils.loadImg_101(context.applicationContext, list[0], mCircleHeadCladOne)
                GlideUtils.loadImg_101(context.applicationContext, list[1], mCircleHeadCladTwo)
            }
            3 -> {
                mCircleHeadCladOne.visibility = VISIBLE
                mCircleHeadCladTwo.visibility = VISIBLE
                mCircleHeadCladThree.visibility = VISIBLE
                mCircleHeadCladFour.visibility = GONE
                mCircleHeadCladFive.visibility = GONE
                GlideUtils.loadImg_101(context.applicationContext, list[0], mCircleHeadCladOne)
                GlideUtils.loadImg_101(context.applicationContext, list[1], mCircleHeadCladTwo)
                GlideUtils.loadImg_101(context.applicationContext, list[2], mCircleHeadCladThree)
            }
            4 -> {
                mCircleHeadCladOne.visibility = VISIBLE
                mCircleHeadCladTwo.visibility = VISIBLE
                mCircleHeadCladThree.visibility = VISIBLE
                mCircleHeadCladFour.visibility = VISIBLE
                mCircleHeadCladFive.visibility = GONE
                GlideUtils.loadImg_101(context.applicationContext, list[0], mCircleHeadCladOne)
                GlideUtils.loadImg_101(context.applicationContext, list[1], mCircleHeadCladTwo)
                GlideUtils.loadImg_101(context.applicationContext, list[2], mCircleHeadCladThree)
                GlideUtils.loadImg_101(context.applicationContext, list[3], mCircleHeadCladFour)
            }
            5 -> {
                mCircleHeadCladOne.visibility = VISIBLE
                mCircleHeadCladTwo.visibility = VISIBLE
                mCircleHeadCladThree.visibility = VISIBLE
                mCircleHeadCladFour.visibility = VISIBLE
                mCircleHeadCladFive.visibility = VISIBLE
                GlideUtils.loadImg_101(context.applicationContext, list[0], mCircleHeadCladOne)
                GlideUtils.loadImg_101(context.applicationContext, list[1], mCircleHeadCladTwo)
                GlideUtils.loadImg_101(context.applicationContext, list[2], mCircleHeadCladThree)
                GlideUtils.loadImg_101(context.applicationContext, list[3], mCircleHeadCladFour)
                GlideUtils.loadImg_101(context.applicationContext, list[4], mCircleHeadCladFive)
            }
        }
    }
}